﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TuyennvLibrary.Notify.IOS
{
    public class IOSNotify
    {
        public static int SANBOX_HOST = 1;
        public static int PRODUCTION_HOST = SANBOX_HOST + 1;
        public List<NotificationPayload> ListNotification { get; set; }
        public string FileP12 { get; set; }
        public string Password { get; set; }
        public int Host { get; set; }
        public IOSNotify()
        {
            this.FileP12 = string.Empty;
            this.Password = string.Empty;
            this.ListNotification = new List<NotificationPayload>();
        }
        public IOSNotifyResponse Push()
        {
            try
            {
                IOSNotifyResponse response = new IOSNotifyResponse();
                var push = new PushNotification((Host == SANBOX_HOST), FileP12, Password);
                var rejected = push.SendToApple(ListNotification);
                response.Failure = rejected.Count;
                response.Success = ListNotification.Count - response.Failure;
                response.ListDeviceTokenError = rejected;
                return response;
            }
            catch (Exception)
            {
                return new IOSNotifyResponse();
            }

        }
    }
}
